package DecertifiSys;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.InvalidConfigurationException;
import org.mybatis.generator.exception.XMLParserException;
import org.mybatis.generator.internal.DefaultShellCallback;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

@SpringBootApplication
@EnableEurekaClient
public class DecertifisysApplication {

	public static void main(String[] args) {
		SpringApplication.run(DecertifisysApplication.class, args);



//        try {
//            generator();
//        } catch (SQLException e) {
//            e.printStackTrace();
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        } catch (InvalidConfigurationException e) {
//            e.printStackTrace();
//        }


    }


    /**
     *
     * mybatics 逆向工程 生成 mapper dao  bean
     * */
    public static void generator()throws SQLException, InterruptedException, InvalidConfigurationException{
        List<String> warnings = new ArrayList <String>();
        boolean overwrite = true;
        File configfile = new File("/Users/zhoumeineng/Desktop/AI-merchant-sys/decertifisys/src/main/resources/generator/genreatorConfig.xml");
        ConfigurationParser configurationParser = new ConfigurationParser(warnings);
        try {
            Configuration configuration = configurationParser.parseConfiguration(configfile);
            DefaultShellCallback callback = new DefaultShellCallback(overwrite);
            MyBatisGenerator myBatisGenerator = new MyBatisGenerator(configuration,callback,warnings);
            myBatisGenerator.generate(null);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (XMLParserException e) {
            e.printStackTrace();
        }
    }

	@Bean
    @LoadBalanced
    public RestTemplate restTemplate(){
	    return new RestTemplate();
    }
}
